package com.qyhl.webtv.module_circle.circle.topicdetail;

import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.basiclib.utils.DateUtils;
import com.qyhl.webtv.basiclib.utils.NotchSizeUtil;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.basiclib.utils.dialog.SingleChoiceDialog;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.entity.circle.CircleHomeBean;
import com.qyhl.webtv.commonlib.entity.intergral.CoinBean;
import com.qyhl.webtv.commonlib.service.UserService;
import com.qyhl.webtv.commonlib.utils.DoubleClickBackToContentTopListener;
import com.qyhl.webtv.commonlib.utils.action.ActionConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionLogUtils;
import com.qyhl.webtv.commonlib.utils.eventbus.BusFactory;
import com.qyhl.webtv.commonlib.utils.eventbus.Event;
import com.qyhl.webtv.commonlib.utils.router.RouterManager;
import com.qyhl.webtv.commonlib.utils.view.editbar.EditBar;
import com.qyhl.webtv.commonlib.utils.view.editbar.EditBarOnClickListenerImpl;
import com.qyhl.webtv.module_circle.R;
import com.qyhl.webtv.module_circle.R2;
import com.qyhl.webtv.module_circle.utils.itemview.ItemPictureView;
import com.qyhl.webtv.module_circle.utils.itemview.ItemTextView;
import com.qyhl.webtv.module_circle.utils.itemview.ItemVideoView;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.umeng.analytics.MobclickAgent;
import com.weavey.loading.lib.LoadingLayout;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.wrapper.EmptyWrapper;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import es.dmoral.toasty.Toasty;

/**
 * Created by qyhl on 2018/2/6.
 * 话题详情 circle_topic
 */

@Route(path = ARouterPathConstant.CIRCLE_TOPIC)
public class TopicDetailActivity extends BaseActivity implements TopicDetailContract.TopicDetailView {

    @BindView(R2.id.cover)
    ImageView cover;
    @BindView(R2.id.title)
    TextView title;
    @BindView(R2.id.join_num)
    TextView joinNum;
    @BindView(R2.id.summary)
    TextView summary;
    @BindView(R2.id.topic_toolbar)
    Toolbar toolbar;
    @BindView(R2.id.collapsing_layout)
    CollapsingToolbarLayout toolbarLayout;
    @BindView(R2.id.app_bar)
    AppBarLayout appBar;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.refresh)
    SmartRefreshLayout refresh;
    @BindView(R2.id.load_mask)
    LoadingLayout loadMask;
    @BindView(R2.id.editbar)
    EditBar editbar;

    private TopicDetailPresenter mPresenter;

    @Autowired(name = "id")
    String tagId;

    private String lastId = "0";

    private MultiItemTypeAdapter mAdapter;

    private List<CircleHomeBean> mDataList;

    private CircleHomeBean.TagList mTagBean;

    private CollapsingToolbarLayoutState state;
    private boolean editbarEnable = true;
    /**
     * 是否为全屏
     */
    private boolean isNotch;

    private int mToolBarState = 0;

    private enum CollapsingToolbarLayoutState {
        EXPANDED,
        COLLAPSED,
        INTERNEDIATE
    }

    private CircleHomeBean mBean;
    private int postion, uPos;
    private String date, content;

    private EmptyWrapper emptyWrapper;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.Transparent));
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        } else {
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }


    }


    @Override
    protected int getContentView() {
        return R.layout.circle_activity_circle_topic;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {

    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        mPresenter = new TopicDetailPresenter(this);
        initView();
        mPresenter.getBaseInfo(tagId);
    }

    @Override
    protected void setListener() {
        setListeners();
    }

    /**
     * 初始化
     */
    private void initView() {

        //刘海屏处理
        isNotch = NotchSizeUtil.hasNotchInScene(this);
        if (isNotch) {
            CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
            lp.setMargins(0, StringUtils.dip2px(this, 40), 0, 0);
            toolbar.setLayoutParams(lp);
            LinearLayout.LayoutParams titleLp = (LinearLayout.LayoutParams) title.getLayoutParams();
            titleLp.setMargins(0, StringUtils.dip2px(this, 40), 0, 0);
            title.setLayoutParams(titleLp);
        }

        loadMask.setStatus(LoadingLayout.Loading);
        BusFactory.getBus().register(this);
        editbar.hideShare(true);
        editbar.hideComment(true);
        editbar.hideCollect(true);
        mDataList = new ArrayList<>();

        refresh.setRefreshHeader(new MaterialHeader(this));
        refresh.setRefreshFooter(new ClassicsFooter(this));
        refresh.setEnableLoadMore(true);

        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbarLayout.setFocusable(false);
        toolbarLayout.setCollapsedTitleGravity(Gravity.CENTER_HORIZONTAL);

        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        //添加自定义分割线
        DividerItemDecoration divider = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this, R.drawable.circle_recycleview_divider));
        recyclerView.addItemDecoration(divider);


        mAdapter = new MultiItemTypeAdapter(this, mDataList);
        mAdapter.addItemViewDelegate(new ItemPictureView(this, true));
        mAdapter.addItemViewDelegate(new ItemTextView(this, true));
        mAdapter.addItemViewDelegate(new ItemVideoView(this, true));

        emptyWrapper = new EmptyWrapper(mAdapter);
        emptyWrapper.setEmptyView(R.layout.circle_layout_circle_content_emptyview);
        recyclerView.setAdapter(emptyWrapper);
    }

    /**
     * 监听
     */
    private void setListeners() {
        //重载
        loadMask.setOnReloadListener(new LoadingLayout.OnReloadListener() {
            @Override
            public void onReload(View v) {
                loadMask.setReloadButtonText("加载中...");
                mPresenter.getBaseInfo(tagId);
            }
        });

        //刷新
        refresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                mPresenter.getBaseInfo(tagId);
            }
        });

        //加载更多
        refresh.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                mPresenter.getDatas(tagId, lastId);
            }
        });

        //item点击跳转
        mAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("id", mDataList.get(position).getId() + "");
                RouterManager.router(ARouterPathConstant.CIRCLE_DETAIL,bundle);

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (verticalOffset == 0) {
                    if (state != CollapsingToolbarLayoutState.EXPANDED) {
                        state = CollapsingToolbarLayoutState.EXPANDED;//修改状态标记为展开
                        mToolBarState = 0;
                        toolbarLayout.setTitle("");
                        toolbarLayout.setExpandedTitleTextColor(ContextCompat.getColorStateList(TopicDetailActivity.this, R.color.white));
                        toolbar.setNavigationIcon(R.drawable.small_video_back_btn);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            Window window = getWindow();
                            window.setStatusBarColor(0x00000000);
                            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                        }
                        invalidateOptionsMenu();
                    }
                } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                    if (state != CollapsingToolbarLayoutState.COLLAPSED) {
                        //设置title为EXPANDED
                        toolbarLayout.setTitle("#" + mTagBean.getName() + "#");
                        mToolBarState = 1;
                        toolbarLayout.setCollapsedTitleTextColor(ContextCompat.getColor(TopicDetailActivity.this, R.color.global_black_lv1));
                        //修改状态标记为折叠
                        state = CollapsingToolbarLayoutState.COLLAPSED;
                        toolbar.setNavigationIcon(R.drawable.btn_back_default);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            Window window = getWindow();
                            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                            window.setStatusBarColor(0xffffffff);
                            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                        }
                    }
                    invalidateOptionsMenu();
                } else {
                    if (state != CollapsingToolbarLayoutState.INTERNEDIATE) {
                        toolbarLayout.setTitle("");
                        state = CollapsingToolbarLayoutState.INTERNEDIATE;//修改状态标记为中间
                    }
                }

            }
        });

        editbar.setEditBarOnClickListener(new EditBarOnClickListenerImpl() {
            @Override
            public void onSend() {
                if (editbarEnable) {
                    editbarEnable = false;
                    CommonUtils.getInstance().isLogin(new UserService.LoginCallBack() {
                        @Override
                        public void login(boolean isLogin) {
                            if (isLogin) {
                                content = editbar.getContent();
                                String dstUsername;
                                if (StringUtils.isNotEmpty(content)) {
                                    if (uPos == -1) {
                                        dstUsername = "";
                                    } else {
                                        dstUsername = mBean.getPostList().get(uPos).getUser().getUsername();
                                    }
                                    date = DateUtils.getCurrentTime();
                                    mPresenter.sendComment(mBean.getId() + "", content, dstUsername);
                                    editbar.clearContent();
                                } else {
                                    Toasty.normal(TopicDetailActivity.this, "评论不能为空！").show();
                                    editbarEnable = true;
                                }
                            } else {
                                Toasty.normal(TopicDetailActivity.this, "尚未登录或登录已失效！").show();
                                RouterManager.routerLogin(TopicDetailActivity.this, 0);
                                editbarEnable = true;
                            }
                        }

                        @Override
                        public void error(String s) {
                            editbarEnable = true;
                        }
                    });


                }

            }
        });
        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (RecyclerView.SCROLL_STATE_DRAGGING == newState && editbar.getVisibility() == View.VISIBLE) {
                    editbar.clearContent();
                    editbar.setVisibility(View.GONE);
                }
            }
        });
        /**
         * 双击返回顶部
         */
        toolbar.setOnClickListener(new DoubleClickBackToContentTopListener(new DoubleClickBackToContentTopListener.IBackToContentTopView() {
            @Override
            public void backToContentTop() {
                recyclerView.scrollToPosition(0);
            }
        }));
    }

    /**
     * 设置内容
     *
     * @param beanList
     * @param isMore
     */
    @Override
    public void setDatas(List<CircleHomeBean> beanList, boolean isMore) {
        loadMask.setStatus(LoadingLayout.Success);
        loadMask.setReloadButtonText("点击重试~~");

        if (beanList != null && beanList.size() > 0) {
            lastId = beanList.get(beanList.size() - 1).getId() + "";
        }

        if (isMore) {
            refresh.finishLoadMore();
            mDataList.addAll(beanList);
        } else {
            if (beanList != null && beanList.size() > 0) {
                refresh.setEnableLoadMore(true);
            } else {
                refresh.setEnableLoadMore(false);
            }
            refresh.finishRefresh();
            mDataList.clear();
            mDataList.addAll(beanList);
        }

        emptyWrapper.notifyDataSetChanged();
    }

    /**
     * 设置基本内容
     *
     * @param bean
     */
    @Override
    public void setBase(CircleHomeBean.TagList bean) {
        mTagBean = bean;
        //标题
        title.setText("#" + mTagBean.getName() + "#");

        //封面图
        Glide.with(this)
                .load(mTagBean.getPic())
                .into(cover);

        //摘要
        if (StringUtils.isNotEmpty(mTagBean.getDesc())) {
            summary.setVisibility(View.VISIBLE);
            summary.setText(mTagBean.getDesc());
        } else {
            summary.setVisibility(View.GONE);
        }


        lastId = "0";

        mPresenter.getDatas(tagId, lastId);
    }

    /**
     * 无网络
     *
     * @param msg
     */
    @Override
    public void setNetError(String msg) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        loadMask.setStatus(LoadingLayout.No_Network);
        loadMask.setReloadButtonText("点击重试~~");
        loadMask.setNoNetworkText(msg);
    }

    /**
     * 出错
     *
     * @param msg
     */
    @Override
    public void setError(String msg) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        loadMask.setStatus(LoadingLayout.Error);
        loadMask.setReloadButtonText("点击重试~~");
        loadMask.setErrorText(msg);
    }

    /**
     * 无内容
     *
     * @param msg
     */
    @Override
    public void setEmpty(String msg) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        loadMask.setStatus(LoadingLayout.Empty);
        loadMask.setReloadButtonText("点击重试~~");
        loadMask.setEmptyText(msg);
    }


    @Override
    public void setLog(String msg) {
        refresh.finishLoadMore();
        Log.i("info", msg);
    }

    @Override
    public void showMessage(String msg) {
        refresh.finishLoadMore();
        Toasty.normal(this, msg).show();
    }

    /**
     * 基本内容获取失败
     *
     * @param msg
     */
    @Override
    public void setBaseError(String msg) {
        loadMask.setStatus(LoadingLayout.Error);
        loadMask.setErrorText(msg);
        loadMask.setReloadButtonText("点击重试~~");
    }

    @Override
    public void commentSuccess(int postId, String msg, int code) {
        Toasty.normal(this, msg).show();

        //0评论  1回复
        CircleHomeBean.PostList postBean;
        String nickName = CommonUtils.getInstance().getNickName();
        String userName = CommonUtils.getInstance().getUserName();
        String headicon = CommonUtils.getInstance().getUserLogo();
        if (code == 0) {
            postBean = new CircleHomeBean.PostList(date, postId, 1, content, new CircleHomeBean.User(nickName, headicon, userName, false), mBean.getUser());
        } else {
            postBean = new CircleHomeBean.PostList(date, postId, 2, content, new CircleHomeBean.User(nickName, headicon, userName, false), mBean.getPostList().get(uPos).getUser());
        }
        if (mBean.getPostList() != null && mBean.getPostList().size() >= 4) {
            mBean.getPostList().add(0, postBean);
            mBean.getPostList().remove(3);
        } else if (mBean.getPostList() == null) {
            List<CircleHomeBean.PostList> beanList = new ArrayList<>();
            beanList.add(postBean);
            mBean.setPostList(beanList);
        } else {
            mBean.getPostList().add(0, postBean);
        }
        mBean.setPostCount(mBean.getPostCount() + 1);
        mDataList.set(postion, mBean);
        emptyWrapper.notifyDataSetChanged();
        editbar.clearContent();
        editbar.setVisibility(View.GONE);
        editbarEnable = true;
        String integralSwitch = CommonUtils.getInstance().getIntergralSwitch();
        if (integralSwitch.equals("1")) {
            getCommentCoin();
        }
    }


    @Override
    public void getCoinError(String msg){
        Log.i("coin_error", msg);
    }

    @Override
    public void getCoinSuccess(CoinBean coinBean){
        Toasty.normal(TopicDetailActivity.this, "成功评论，获得" + coinBean.getCoin() + "金币！").show();
    }
    /**
     * 评论获取金币
     */
    private void getCommentCoin() {

        mPresenter.getCommentCoin();

    }

    @Override
    public void commentError(String msg) {
        Toasty.normal(this, msg).show();
        editbarEnable = true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BusFactory.getBus().unregister(this);
        GSYVideoManager.releaseAllVideos();
    }


    /**
     * 评论事件
     *
     * @param event
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void commentMessage(Event.CommentEvent event) {
        if (event != null) {

            mBean = event.getBean();
            postion = event.getPostion();
            uPos = event.getuPos();
            editbar.setVisibility(View.VISIBLE);
            editbar.changeStateSend(this);
            if (uPos < 0) {
                editbar.setEditTextHint("评论");
            } else {
                editbar.setEditTextHint("回复:" + mBean.getPostList().get(uPos).getUser().getNickName());
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void praiseMessage(Event.praiseRefreshEvent event) {
        if (event != null) {
            int topicId = event.getTopicId();
            for (int i = 0; i < mDataList.size(); i++) {
                if (mDataList.get(i).getId() == topicId) {
                    if (event.getType() == 1) {
                        mDataList.get(i).setLove(true);
                        mDataList.get(i).setLoveCount(mDataList.get(i).getLoveCount() + 1);
                    } else {
                        mDataList.get(i).setLove(false);
                        mDataList.get(i).setLoveCount(mDataList.get(i).getLoveCount() - 1);
                    }
                }
            }
            emptyWrapper.notifyDataSetChanged();
        }
    }

    /**
     * 登录状态改变事件
     *
     * @param event
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getMessage(Event.LoginMessage event) {
        if (event != null) {
            mPresenter.getBaseInfo(tagId);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refresh(Event.circleRefresh event) {
        if (event != null && mDataList != null) {
            for (int i = 0; i < mDataList.size(); i++) {
                if (mDataList.get(i).getId() == event.getTopicId()) {
                    mDataList.remove(i);
                    mAdapter.notifyDataSetChanged();
                }
            }
        }
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (GSYVideoManager.backFromWindowFull(this)) {
                    return true;
                } else {
                    finish();
                }
            default:
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onResume() {
        super.onResume();
        //baidu
        //umeng
        MobclickAgent.onPageStart("圈子话题");
        MobclickAgent.onResume(this);
        GSYVideoManager.onResume();
        ActionLogUtils.getInstance().onResume(this, ActionConstant.CIRCLETOPIC);
    }

    @Override
    public void onPause() {
        super.onPause();
        //baidu
        //umeng
        MobclickAgent.onPageEnd("圈子话题");
        MobclickAgent.onPause(this);
        GSYVideoManager.onPause();
        ActionLogUtils.getInstance().onPause(this, ActionConstant.CIRCLETOPIC);
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {


        // 动态设置ToolBar状态
        switch (mToolBarState) {
            case 0:
                menu.findItem(R.id.add_circle).setVisible(false);
                menu.findItem(R.id.add_circle_white).setVisible(true);
                break;
            case 1:
                menu.findItem(R.id.add_circle).setVisible(true);
                menu.findItem(R.id.add_circle_white).setVisible(false);
                break;
            default:
                break;
        }
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.circle_topic_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int i = item.getItemId();//屏蔽
        if (i == R.id.add_circle || i == R.id.add_circle_white) {
            new SingleChoiceDialog.Builder(this).setTitle("类型", R.color.global_gray_lv2)
                    .addList(new String[]{"图文", "视频"})
                    .setCancelTextColor(R.color.global_base)
                    .setOnItemClickListener((title, position) -> {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", tagId);
                        switch (position) {
                            case 0:
                                bundle.putInt("type", 3);
                                break;
                            case 1:
                                bundle.putInt("type", 4);
                                break;
                            default:
                                break;
                        }
                        toCircleAdd(bundle);
                    })
                    .show();

        } else if (i == android.R.id.home) {
            finish();
        } else {
        }
        return super.onOptionsItemSelected(item);
    }


    private void toCircleAdd(Bundle bundle) {
        CommonUtils.getInstance().isLogin(new UserService.LoginCallBack() {
            @Override
            public void login(boolean isLogin) {
                if( isLogin ){
                    RouterManager.router(ARouterPathConstant.CIRCLE_ADD,bundle);
                }else{
                    RouterManager.routerLogin(TopicDetailActivity.this,0);
                }
            }
            @Override
            public void error(String s) {
                RouterManager.routerLogin(TopicDetailActivity.this,0);
            }
        });
    }

}
